package com.raft.core.rpc.message;

import java.io.Serializable;

public class RequestVoteResult implements Serializable {

    /**
	 *
	 */
	private static final long serialVersionUID = 430545283290030689L;
	private int term; // 当前的term，帮助Candidate节点更新自己的term
    // term一方面可以告诉Candidate节点当前最新的term，也可以避免系统受过去term消息的影响。比如节点在term1时变成了Candidate节点，没有收到响应，则再次变成Candidate节点，发送term2的RequestVote消息，
    // 此时收到term1的RequestVote响应时会直接忽略，因为响应中的term1比当前term(即term2)小
    private boolean voteGranted; // 如果为true，表示Candidate节点获取了选票
    // 一般voteGranted为true时，term就是Candidate请求时的term；如果为false，则是接收Candidate请求的Follower节点的term

    public RequestVoteResult(int term, boolean voteGranted) {
        this.term = term;
        this.voteGranted = voteGranted;
    }

    public int getTerm() {
        return term;
    }

    public void setTerm(int term) {
        this.term = term;
    }

    public boolean isVoteGranted() {
        return voteGranted;
    }

    public void setVoteGranted(boolean voteGranted) {
        this.voteGranted = voteGranted;
    }

    @Override
    public String toString() {
        return "RequestVoteResult{" + "term=" + term +
                ", voteGranted=" + voteGranted +
                '}';
    }
}
